   package service;

import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.ccc.model.Parameter;
import com.ccc.model.User;
import com.ccc.service.ParameterService;
import com.ccc.service.UserService;
import com.ccc.util.dao.UtilDao;
import com.ccc.util.page.PageView;

public class UserServiceTest {
	
	private static UserService userService;
	private static UtilDao utilDao;
	private HibernateTemplate hibernateTemplate;
	private static ParameterService parameterService;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		try {
			ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
			userService = (UserService)cxt.getBean("userService");
			utilDao = (UtilDao) cxt.getBean("utilDao");
			parameterService = (ParameterService) cxt.getBean("parameterService");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void addUser(){
		for(int i=1;i<41;i++){
		User user = new User();
		user.setUserName(i+"");
		user.setUserPass(i+"");
		userService.register(user);}
	}
	
	@Test
	public void updateUser(){
		User user = userService.findUser(1);
		user.setUserName("ff");
		user.setUserPass("kshj");
		System.out.println(user.getUserName());
	}
	
	@Test
	public void userListTest(){
		PageView<User> pageView = userService.listUser(0,null);
		List<User> userList = pageView.getRecords();
		for(User u :userList){
			System.out.println("userName=" + u.getUserName() +" userPassword=" + u.getUserPass());
		}
	}
	
	@Test
	public void findFirstUser(){
		System.out.println(userService.findFirstUser());
	}
	
	@Test
	public void addParameter(){
		Parameter parameter = new Parameter();
		parameter.setId(1);
		parameter.setInterestRate(6);
		parameter.setLoanBase(2);
		parameter.setTaxRate(6);
		parameterService.addParameter(parameter);
	}
}
